import twophase.solver as sv
from pydantic import BaseModel


class RubikCube_model(BaseModel):
    cubestring: str


def colorToSign(s):
    s = s.replace("白", "U").replace("红", "F").replace("绿", "L")
    s = s.replace("蓝", "R").replace("黄", "D").replace("橙", "B")
    return s


def signToSyntax(s):
    if s.startswith("Error:"):
        return s
    s = s.replace("U", "上").replace("F", "前").replace("L", "左")
    s = s.replace("R", "右").replace("D", "下").replace("B", "后")
    return s


def rubik(data):
    # 上白 前红 左绿 右蓝 下黄 后橙
    cubestring = data.cubestring
    cubestring = colorToSign(cubestring)
    return {"result": signToSyntax(sv.solve(cubestring, 19, 2))}
